package com.sys.platform.common.utils;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;

import java.util.Arrays;
import java.util.List;

//SDK接口说明,SfxGateSDK.dll
public interface SfxGateSDK extends Library {

    SfxGateSDK ins = Native.load(System.getProperty("user.dir") + "\\lib\\SfxGate.dll", SfxGateSDK.class);


    /**
     * 分配一个道闸实例
     *
     * @param type
     * @param ip
     * @param url
     * @return
     */
    Pointer sfxAllocGate(int type, String ip, int port, String url);

    /**
     * 开闸
     *
     * @param gate
     * @return
     */
    int sfxOpenGate(Pointer gate);

    /**
     * 关闸
     *
     * @param gate
     * @return
     */
    int sfxCloseGate(Pointer gate);

    /**
     * 释放一个道闸实例
     *
     * @param gate
     */
    void sfxFreeGate(Pointer gate);


    // 获取白名单
    Pointer sfxGetGateWhilteList(Pointer pointer);

    int sfxGetGateWhilteCount(Pointer gate);

    // 添加白名单
    int sfxAddPlateGate(Pointer pointer, String plate, SfxDate date);

    //删除白名单
    int sfxDelPlateGate(Pointer pointer, String plate);


    public static class SfxDate extends Structure {
        public int year;
        public byte month;
        public byte day;
        public byte hour;
        public byte min;
        public byte sec;

        public static class ByReference extends SfxDate implements Structure.ByReference {
        }

        public static class ByValue extends SfxDate implements Structure.ByValue {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList(new String[]{"year", "month", "day", "hour", "min", "sec"});
        }
    }

    public static class SfxGatePlate extends Structure {
        public SfxGatePlate(Pointer plate) {
            super(plate);
            read();
        }

        public byte[] plate = new byte[16];
        public SfxDate expired;

        public static class ByReference extends SfxGatePlate implements Structure.ByReference {
            public ByReference(Pointer plate) {
                super(plate);
            }
        }

        public static class ByValue extends SfxGatePlate implements Structure.ByValue {
            public ByValue(Pointer plate) {
                super(plate);
            }
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList(new String[]{"plate", "expired"});
        }

    }


}



